﻿using Project.API.Models;
using Project.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Project.API.Controllers
{
    public class SaleController : ApiController
    {

        //GET: api/Sale
        [Route("Api/Sale")]
        public ResultData<List<SaleDto>> Get()
        {
            int count = 0;
            var list = new SaleBll().Query();

            var data = from r in list
                       select new SaleDto
                       {
                           Xsid = r.Xsid,
                           Type = r.Type,
                           Total = r.Total,
                           Quantity = r.Quantity,
                           Ymonth = r.Ymonth,
                           gtid = r.GoodsType.gtId,
                           name = r.GoodsType.name
                       };


            ResultData<List<SaleDto>> result = new ResultData<List<SaleDto>>();
            result.code = 0;
            result.msg = "ok";
            result.data = data.ToList();

            return result;
        }
        [Route("Api/SalePage")]
        public ResultPageList<SaleDto> Get(int page, int limit)
        {
            int count = 0;
            var list = new SaleBll().GetSaleByPage(page, limit, out count);

            var data = from r in list
                       select new SaleDto
                       {
                           Xsid = r.Xsid,
                           Type = r.Type,
                           Total = r.Total,
                           Quantity = r.Quantity,
                           Ymonth = r.Ymonth,
                           gtid = r.GoodsType.gtId,
                           name = r.GoodsType.name
                       };

            ResultPageList<SaleDto> result = new ResultPageList<SaleDto>();
            result.code = 0;
            result.msg = "ok";
            result.count = count;
            result.data = data.ToList();

            return result;
        }
        //GET: api/Sale/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Sale
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/Sale/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/Sale/5
        public void Delete(int id)
        {
        }
    }
}
